﻿using CSharpDesign.DAL;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;

namespace CSharpDesign.BLL
{
    public class NewsService
    {
        SqlHelper sqlHelper = new SqlHelper();
        /// <summary>
        /// 获取新闻列表
        /// </summary>
        /// <returns></returns>
        public DataSet GetNewsList()
        {
            string sql = "select * from News   order by Click desc";
            return CommonHelper.GetDataByAdapter(sql);
        }

        /// <summary>
        /// 删除新闻
        /// </summary>
        /// <param name="ID"></param>
        /// <returns></returns>
        public Boolean DelectNews(string ID)
        {
            try
            {
                string sql = "delete  from News  where  id='" + ID + "'";
                sqlHelper.RunSql(sql);
                return true;
            }
            catch
            {
                return false;
            }
        }

        /// <summary>
        /// 根据类型获取新闻
        /// </summary>
        /// <param name="strTop"></param>
        /// <param name="type"></param>
        /// <returns></returns>
        public DataSet GetNewsByType(string strTop, string type)
        {
            string sql = "select  " + strTop + "  * from [News] where typeid='" + type + "'  ";
            return CommonHelper.GetDataByAdapter(sql);
        }

        /// <summary>
        /// 修改新闻
        /// </summary>
        /// <param name="name"></param>
        /// <param name="content"></param>
        /// <param name="typeid"></param>
        /// <param name="TypeName"></param>
        /// <param name="dID"></param>
        public void UpdataNews(string name, string content, string typeid, string TypeName, string dID)
        {
            string sql = "update News set name='" + name + "',content='" + content + "',typeid='" + typeid + "',TypeName='" + TypeName + "' where id=" + dID;
            sqlHelper.RunSql(sql);
        }

        /// <summary>
        /// 添加新闻
        /// </summary>
        /// <param name="name"></param>
        /// <param name="content"></param>
        /// <param name="typeid"></param>
        /// <param name="TypeName"></param>
        public void InsertNews(string name, string content, string typeid, string TypeName)
        {
            string sql = "insert into News(name,content,typeid,TypeName) values('" + name + "','" + content + "','" + typeid + "','" + TypeName + "')";
            sqlHelper.RunSql(sql);
        }
    }
}